package com.scalar.chiptrack.commons.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

/**
 * User: Ganesh
 * Date: Apr 29, 2008
 * Time: 11:25:58 AM
 */

public class ResultRowManager {
    protected ArrayList rows;

    public ResultRowManager(ResultSet rs){
        try{
            /*System.out.println("in rowmanger constructor");
            System.out.println("result set in row manager"+rs);*/
            if(rs!=null){
                rows = new ArrayList();

                    while(rs.next())
                    {
                        HashMap rowMap = new HashMap();
                        ResultSetMetaData metaData = rs.getMetaData();
                        int columnCount = metaData.getColumnCount();
                        for(int i=0;i<columnCount;i++)
                        {
                            String columnName = metaData.getColumnName((i+1));
                            rowMap.put(columnName,rs.getString((i+1)));
                        }
                        rows.add(new RowResultBeanImpl(rowMap));
                    }
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.out.println("exception in ResultRowManager");
        }
    }

    /**
    * Gets rows
    * @return rows ArrayList
    */
    public ArrayList getRows()
    {
       return rows;
    }
    /**
    * Sets rows
    *@param rows ArrayList
    */
    public void setRows(ArrayList rows)
    {
       this.rows = rows;
    }
}
